package jsj.mynet;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class MyReceiveThread implements Runnable {
	DatagramSocket ds;
	
	public MyReceiveThread() {
		super();
	}

	public MyReceiveThread(DatagramSocket ds) {
		super();
		this.ds = ds;
	}

	@Override
	public void run() {
		byte[] bys = new byte[1024];
		DatagramPacket dp = new DatagramPacket(bys, bys.length);
		
		while(true){
			try {
				ds.receive(dp);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			String ip = dp.getAddress().getHostAddress();
			int port = dp.getPort();
			String text = new String(dp.getData(), 0, dp.getLength());
			
			System.out.println(ip+":"+port+":"+text);
		}

	}

}
